﻿using Bible.Core.Interface;
using Bible.Core.Model;
using NUnit.Framework;
using System.Collections.Generic;

namespace Bible.Core.UnitTests.Chapter_Tests
{
    [TestFixture]
    [Category("Core.Model.Chapter")]
    [Description("Chapter constructed with default constructor should")]
    public class Chapter_constructed_with_default_constructor_should
    {
        [Test]
        [Description(" have a non null Verses property")]
        public void _have_a_non_null_Verses_property()
        {
            Assert.That(new Chapter().Verses, Is.Not.Null,
                "Chapter.Verses should not be null.");
        }

        [Test]
        [Description(" have 0 verses")]
        public void _have_0_verses()
        {
            Assert.That(new Chapter().Verses, Is.Empty,
                "Chapter.Verses should be empty.");
        }
    }

    [TestFixture]
    [Category("Core.Model.Chapter")]
    [Description("Chapter constructed with verses parameter should")]
    public class Chapter_constructed_with_verses_parameter_should
    {
        [Test, TestCaseSource("VerseCountCases")]
        [Description(" have a Verse list that is not empty")]
        public void _have_a_Verse_list_that_is_not_empty(int verseCount)
        {
            var chapter = CreateChapterWithVerses(verseCount);
            Assert.That(chapter.Verses, Is.Not.Empty,
                "Chapter.Verses should not be empty.");
        }

        [Test, TestCaseSource("VerseCountCases")]
        [Description(" have the same Verses count as the constructor parameter list")]
        public void _have_the_same_Verses_count_as_the_constructor_parameter_list(int verseCount)
        {
            var chapter = CreateChapterWithVerses(verseCount);
            Assert.That(chapter.Verses.Count, Is.EqualTo(verseCount),
                "Chapter.Verses should have a count of 1.");
        }

        [Test, TestCaseSource("VerseCountCases")]
        [Description(" have all Verses of type Verse")]
        public void _have_all_Chapters_of_type_Chapter(int verseCount)
        {
            var chapter = CreateChapterWithVerses(verseCount);
            foreach (var verse in chapter.Verses)
            {
                Assert.That(verse, Is.TypeOf<Verse>(),
                    "All objects in Chapter.Verses should be of type Verse");
            }
        }

        private static int[] VerseCountCases = new int[] { 1, 250 };

        #region Test Helpers

        public IChapter CreateChapterWithVerses(int verseCount)
        {
            var verses = new List<IVerse>();
            for (int i = 0; i < verseCount; i++)
            {
                verses.Add(new Verse());
            }
            return new Chapter(verses);
        }

        #endregion Test Helpers
    }
}